# 格子对象
extends Area2D

var planted = false
var Game
signal subsun


func _ready():
	Game = get_tree().current_scene.get_node(".")
	connect("subsun",get_tree().current_scene.get_node("Sun/Label"),"sub")
	pass 

# warning-ignore:unused_argument
# warning-ignore:unused_argument
func _on_place_input_event(viewport, event, shape_idx):
	if event is InputEventMouseButton:
		if event.is_pressed() and event.button_index == BUTTON_LEFT:
			#get_tree().current_scene.get_node("Game").selected_plant.queue_free()
			if !planted:
				planted = true
				if Game.selected_Object.name == "sunflower":
					var Sunflower = load("res://object/SunFlower.tscn").instance()
					add_child(Sunflower)
					emit_signal("subsun",Game.selected_Object.cost)
					
				elif Game.selected_Object.name == "wandou":
					var Wandou = load("res://object/Wandou.tscn").instance()
					add_child(Wandou)
					emit_signal("subsun",Game.selected_Object.cost)
				
				elif Game.selected_Object.name == "jinweijianguo":
					var Jinwei = load("res://object/Jinweijianguo.tscn").instance()
					add_child(Jinwei)
					emit_signal("subsun",Game.selected_Object.cost)
				if is_instance_valid(Game.selected_plant):
					Game.selected_plant.queue_free()
			elif planted and Game.use_shovel == true:
				print_debug("恢复种植")
				planted = false
	pass
